
from curses import A_BOLD, A_NORMAL
import curses
import conf

# curses stuff
def centrex(msg):
    return conf.SCREEN_W/2 - len(msg)/2

def boldcentred(line, msg):
    conf.screen.addstr(line, centrex(msg), msg, curses.A_BOLD)

def normcentred(line, msg):
    conf.screen.addstr(line, centrex(msg), msg)

def pcentred(line, *parts):
    totallen = reduce(lambda a,b: a+b, [len(p[1]) for p in parts])
    try:
        conf.screen.move(line, conf.SCREEN_W/2 - totallen/2)
    except curses.error:
        conf.screen.move(line, 0)
    for flags, text in parts:
        try:
            conf.screen.addstr(text, flags)
        except curses.error:
            continue

def clrline(line):
    conf.screen.hline(line, 0, ord(' '), conf.SCREEN_W)
